package com.boc.langxiang.ui.activity.common;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import com.boc.langxiang.R;
import com.boc.langxiang.contract.common.ForgetPasswordContract;
import com.boc.langxiang.entity.events.LoginSuccessEvent;
import com.boc.langxiang.entity.response.SmsCodeEntity;
import com.boc.langxiang.presenter.common.ForgetPasswordPresenter;
import com.boc.langxiang.ui.activity.BaseToolBarActivity;
import com.boc.langxiang.ui.activity.MainActivity;
import com.boc.langxiang.util.KeyBoardUtil;
import com.boc.langxiang.util.StringUtil;
import com.boc.langxiang.util.T;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ForgetPassword2Activity extends BaseToolBarActivity implements ForgetPasswordContract.View {

    @BindView(R.id.password1)
    EditText mPassword1;
    @BindView(R.id.password2)
    EditText mPassword2;
    @BindView(R.id.login)
    TextView mLogin;

    private ForgetPasswordContract.Presenter mPresenter;
    private String mPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_password2);
        ButterKnife.bind(this);
        setToolBarTitle("找回密碼");

        Intent intent = getIntent();
        mPhone = intent.getStringExtra("phone");
        mPresenter = new ForgetPasswordPresenter(this);
    }

    @OnClick(R.id.login)
    public void onClick() {
        KeyBoardUtil.closeKeybord(this);
        String pwd1 = mPassword1.getText().toString();
        if (StringUtil.isEmpty(pwd1)) {
            T.showShort(mContext, "请输入新密码");
            return;
        }
        String pwd2 = mPassword2.getText().toString();
        if (StringUtil.isEmpty(pwd2)) {
            T.showShort(mContext, "请输入确认密码");
            return;
        }

        if (!pwd1.equals(pwd2)) {
            T.showShort(mContext, "两次密码输入不一致");
            return;
        }

        mPresenter.accountFindPwd(mPhone, pwd1, pwd2);
    }

    @Override
    public void onGetSmsCodeSuccess(SmsCodeEntity smsCodeEntity) {

    }

    @Override
    public void loginSuccess() {
        T.showShort(mContext, "密码修改成功!");
        startActivity(new Intent(mContext, MainActivity.class));
        EventBus.getDefault().post(new LoginSuccessEvent());
        finish();
    }

    @Override
    public void smsCodeVerifySuccess() {
        
    }

    @Override
    public void smsCodeVerifyFail(String code, String message) {

    }

    @Override
    public void showLoading() {
        showProgressDialog("提交新密码...");
    }

    @Override
    public void hideLoading() {
        hideDialog();
    }

    @Override
    public void onError(String code, String msg) {

    }
}
